home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / demos / demobook / file_ascii.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  28.0 KB  |  739 lines

  1. /*
  2.  * Copyright 1993, 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. #include <stdio.h>
  18. #include <unistd.h>
  19. #include "exinterfmotif.h"
  20. #include <math.h>
  21. #include <string.h>
  22. #include "exbookglo.h"
  23. #include "exglobals.h"
  24.  
  25. extern struct indexlist *(find_keyword_int() );
  26. extern struct indexlist *(add_keyword() );
  27. extern struct indexlist *find_keyword();
  28. extern struct icntmpltstruct *new_icn();
  29. extern struct grptmpltstruct *new_grp();
  30. extern struct pagestruct *new_pg();
  31. extern void readicon_i();
  32. extern struct filestruct *add_file();
  33. extern struct icntmpltstruct **duplicate_icons;
  34. extern int dup_icn_cnt, max_dup;
  35. extern Boolean append;
  36.  
  37. float ascii_version = .01;
  38.  
  39. int linecount;
  40.  
  41. int find_endofline(char *bigstring)
  42. {
  43.    int count;
  44.  
  45.    count = 0;
  46.    while (bigstring[count] != '\n')
  47.       count++;
  48.    return(count);
  49. }
  50.  
  51. int skip_comments(int filendx, char *thefile)
  52. {
  53.    int len;
  54.  
  55.    while (thefile[filendx] == '#')
  56.       {
  57.       len = find_endofline(&(thefile[filendx]));
  58.       filendx = filendx+len +1;
  59.       linecount++;
  60.       }
  61.    return(filendx);
  62. }
  63.  
  64. void do_format_error(int linecount)
  65. {
  66.    sprintf(msgstring,"Format Problem line %d ascii file %s \n",
  67.          linecount,FileName);
  68.    DialogType = 1;
  69.    popup_Message();
  70. }
  71.  
  72. void check_ending_blanks(char *extract, int len)
  73. {
  74.    int i;
  75.   
  76.    i = len -1;
  77.    while (i > 0 && (extract[i] == ' ' || extract[i] == '\t') )
  78.       {
  79.       extract[i] = '\0';
  80.       i--;
  81.       }
  82. }
  83. void fix_grp_ok(struct grptmpltstruct *grpptr)
  84. {
  85.    Boolean big_ok;
  86.    struct iconstruct *tmpicon;
  87.    
  88.    tmpicon = grpptr->firstpage->fronticons;
  89.    big_ok = FALSE;
  90.    while (tmpicon != NULL)
  91.       {
  92.       if (tmpicon->ok)
  93.          big_ok = TRUE;
  94.       tmpicon = tmpicon->nexticon;
  95.       }
  96.  
  97.    grpptr->ok = big_ok;
  98. }
  99.  
  100.  
  101. Boolean read_ascii(char *thefile, long totalbytes)
  102. {
  103.    int len;
  104.    int cmp_rslt;
  105.    int filendx = 0;
  106.    Boolean FILEERR;
  107.    char *firstline;
  108.    float version_read;
  109.    char *extract;
  110.    int extractlen;
  111.    struct icntmpltstruct *tmpicn;
  112.    struct grptmpltstruct *tmpgrp, *prevgrp;
  113.    Boolean Books, Demos;
  114.    struct filelist *tmpfile;
  115.    struct pagestruct *tmppg;
  116.    struct wordlist *tmpkey;
  117.    struct indexlist *tmpname;
  118.    struct iconstruct *tmpicon;
  119.    float tmpr, tmpg, tmpb;
  120.    int num_conv;
  121.    short x, y;
  122.    int SIDE;
  123.    struct grptmpltstruct *setupgrp;
  124.    struct wordlist *wordptr;
  125.    struct grpliststruct *glist;
  126.    int i;
  127.  
  128.    extract = (char *) malloc(80);
  129.    extractlen = 80;
  130.    tmpicn = NULL;
  131.    setupgrp = NULL;
  132.    tmpgrp = NULL;
  133.    prevgrp = lastgroup;
  134.    tmpfile = NULL;
  135.    tmppg = NULL;
  136.    tmpkey = NULL;
  137.    tmpicon = NULL;
  138.    linecount = 0;
  139.    firstline = (char *)malloc(28 * sizeof (char) );
  140.    strcpy(firstline,"Demobook ASCII file version");
  141.     /* is this a demobook ascii file? */
  142.    filendx = skip_comments(filendx, thefile);
  143.    if (cmp_rslt = strncasecmp(firstline, &(thefile[filendx]), strlen(firstline)) != 0)
  144.       {
  145.       FILEERR = TRUE;
  146.       sprintf(msgstring, "\nError:  %s is not a demobook file.", FileName);
  147.       DialogType = 1;
  148.       popup_Message();
  149.       }
  150.    else
  151.       {
  152.       FILEERR = FALSE;
  153.       filendx = filendx + strlen(firstline) + 1;
  154.       len = find_endofline(&(thefile[filendx]));
  155.       strncpy(extract, &(thefile[filendx]),len);
  156.       extract[len] = '\0';
  157.       version_read = (float)atof(extract);
  158.       filendx = filendx+len +1;
  159.       linecount++;
  160.       if (version_read != ascii_version)
  161.          {
  162.          sprintf(msgstring, "\nError:  bad ascii file version  %f.  Should be %f  \n",version_read, ascii_version);
  163.          DialogType = 1;
  164.          popup_Message();
  165.          }
  166.       else
  167.          {
  168.          dup_icn_cnt = 0;
  169.          max_dup = 32;
  170.          duplicate_icons = (struct icntmpltstruct **) malloc
  171.         ( max_dup* sizeof(struct icntmpltstruct *));
  172.          while (filendx < totalbytes)
  173.             {
  174.             if (thefile[filendx] == '#')
  175.                {
  176.                len = find_endofline(&(thefile[filendx]));
  177.                filendx = filendx+len +1;
  178.                linecount++;
  179.                }
  180.     /* read demos */
  181.             else if ((cmp_rslt = strncasecmp("Demo List", &(thefile[filendx]), 9)) == 0)
  182.                {
  183.                len = find_endofline(&(thefile[filendx]));
  184.                filendx = filendx+len +1;
  185.                linecount++;
  186.                Books = FALSE;
  187.                Demos = TRUE;
  188.                }
  189.     /* read books */
  190.             else if ((cmp_rslt = strncasecmp("Book List", &(thefile[filendx]), 9)) == 0)
  191.                {
  192.                if (lasticon!= NULL)
  193.                    do_iconfiles(lasticon);
  194.                len = find_endofline(&(thefile[filendx]));
  195.                filendx = filendx+len +1;
  196.                linecount++;
  197.                Books = TRUE;
  198.                Demos = FALSE;
  199.                }
  200.             else
  201.                {
  202.                linecount++;
  203.     /* when we get here we can have blank lines; or Name, Command, 
  204.            Icon Files, Files, or Keyword lines for Demos; or Name, Color,
  205.            Keyword, or Demo lines for Books.  Books and Demos lines can
  206.            start with either a tab, or a series of blanks.  */
  207.                len = find_endofline(&(thefile[filendx]));
  208.                if (len >= 5)  /* assume short lines are blank  */
  209.                   {
  210.                   if (thefile[filendx] == '\t')
  211.                      filendx++;
  212.                   else
  213.                      while (thefile[filendx] == ' ')
  214.                         filendx++;
  215.                   if ((cmp_rslt = strncasecmp("Name", &(thefile[filendx]), 4)) == 0)
  216.                      {
  217.                      filendx = filendx + 5;
  218.                      tmpkey = NULL;
  219.                      if (Demos)
  220.                         {
  221.                         if (lasticon!= NULL)
  222.                            do_iconfiles(lasticon);
  223.                         tmpfile = NULL;
  224.                         numberoficons++;
  225.                         tmpicn = new_icn();
  226.                         if (firsticon == NULL)
  227.                            firsticon = tmpicn;
  228.                         else
  229.                            lasticon->nexticntmplt = tmpicn;
  230.                         lasticon = tmpicn;
  231.                         len = find_endofline(&(thefile[filendx]));
  232.                         strncpy(extract, &(thefile[filendx]),len);
  233.                         extract[len] = '\0';
  234.                         check_ending_blanks(extract, len);
  235.                         tmpicn->nameptr = add_keyword(extract);
  236.                         if (tmpicn->nameptr->icon != NULL)  /* ?? duplicate */
  237.                            {
  238.                            if (append) /*found dup while appending a file*/
  239.                               {
  240.                            duplicate_icons[dup_icn_cnt] = tmpicn;
  241.                            dup_icn_cnt++;
  242.                            if (dup_icn_cnt == max_dup)
  243.                               {
  244.                               max_dup = max_dup + 32;
  245.                               duplicate_icons = (struct icntmpltstruct **) realloc
  246.                              ( (void *) duplicate_icons, max_dup* sizeof(struct icntmpltstruct *));
  247.                               } 
  248.                               } 
  249.                            else /* found dup while reading file */
  250.                               { 
  251.                            sprintf(msgstring, "There are two demos with the name <%s>\nin this file.  This will cause problems in adding demos to books.  \n", extract );
  252.                            DialogType = 1;
  253.                            popup_Message();
  254.                               } 
  255.                            }
  256.                         else
  257.                            tmpicn->nameptr->icon = tmpicn;
  258.                         }
  259.                      else if (Books)
  260.                         {
  261.                           /* check to see if previous group had demos in it */
  262.                         if (tmpgrp != NULL && (tmpgrp->firstpage == NULL || tmpgrp->firstpage->frontnumicons == 0))
  263.                            {
  264.                            sprintf(msgstring, " Deleting empty book %s \n",tmpgrp->nameptr->string);
  265.                            DialogType = 1;
  266.                            popup_Message();
  267.                            DeleteGroupFlag = TRUE;
  268.                            deletegroup(tmpgrp);
  269.                            DeleteGroupFlag = FALSE;
  270.                            }
  271.                         else if (tmpgrp != NULL)
  272.                            {
  273. #ifdef DEBUG
  274. printf("\nfixing up group %s  \n", tmpgrp->nameptr->string);
  275. #endif
  276.                            fix_grp_ok(tmpgrp);
  277.                            }
  278.                         if (setupgrp != NULL)
  279.                            {
  280.                            fix_icon_pointers(setupgrp);
  281.                            group_setup(NULL, NULL,setupgrp);
  282.                            }
  283.                         len = find_endofline(&(thefile[filendx]));
  284.                         strncpy(extract, &(thefile[filendx]),len);
  285.                         extract[len] = '\0';
  286.                         check_ending_blanks(extract, len);
  287.                         tmpname = find_keyword(extract);
  288.                         if (tmpname == NULL || tmpname->group == NULL)
  289.                            {
  290.                            prevgrp = tmpgrp;
  291.                         tmpicon = NULL;
  292.                         tmpkey = NULL;
  293.                         tmppg = NULL;
  294.                         SIDE = FRONT;
  295.                         x = 0;
  296.                         y = 3;
  297.                         numberofgroups++;
  298.                         numberofbooks = numberofgroups;
  299.                         tmpgrp = new_grp();
  300.                         if (firstgroup == NULL)
  301.                            firstgroup = tmpgrp;
  302.                         else
  303.                            lastgroup -> nextgrp = tmpgrp;
  304.                         lastgroup = tmpgrp;
  305.                         tmpgrp->prevgrp = prevgrp;
  306.                         tmpgrp->numpages = 1;
  307.                         tmpgrp->nameptr = add_keyword(extract);
  308.                         tmpgrp->nameptr->group = tmpgrp;
  309.                            setupgrp = NULL;
  310.                            }
  311.                         else /* group already exists */
  312.                            {
  313.                            tmpgrp = tmpname->group;
  314.                            tmppg = tmpgrp->lastpage;
  315.                            if (tmppg->backicons == NULL)
  316.                               {
  317.                               tmpicon = tmppg->fronticons;
  318.                               SIDE = FRONT;
  319.                               }
  320.                            else
  321.                               {
  322.                               tmpicon = tmppg->backicons;
  323.                               SIDE = BACK;
  324.                               }
  325.                            while (tmpicon->nexticon != NULL)
  326.                               {
  327.                               x = tmpicon->xposition_ndx;
  328.                               y = tmpicon->yposition_ndx;
  329.                               tmpicon = tmpicon->nexticon;
  330.                               }
  331.                            setupgrp = tmpgrp;
  332.                            tmpkey = tmpgrp->keywords;
  333.                            if (tmpkey != NULL)
  334.                               while (tmpkey->next != NULL)
  335.                                  tmpkey = tmpkey->next;
  336.                            }
  337.                         }
  338.                      }
  339.                   else if ((cmp_rslt = strncasecmp("Command", &(thefile[filendx]), 7)) == 0)
  340.                      {
  341.                      if (Demos)
  342.                         {
  343.                         filendx = filendx + 8;
  344.                         len = find_endofline(&(thefile[filendx]));
  345.                         if (len > extractlen)
  346.                            {
  347.                            free(extract);
  348.                            extract = (char *) malloc( len + 10);
  349. if (extract == NULL)
  350. printf(" extract = NULL\n");
  351.                            extractlen = len + 10;
  352.                            }
  353.                         strncpy(extract, &(thefile[filendx]),len);
  354.                         extract[len] = '\0';
  355.                         set_start_string(tmpicn, extract);
  356.                         }
  357.                      else if (Books)
  358.                         {
  359.                         do_format_error(linecount);
  360.                         }
  361.                      }
  362.                   else if ((cmp_rslt = strncasecmp("AltCommand", &(thefile[filendx]), 10)) == 0)
  363.                      {
  364.                      if (Demos)
  365.                         {
  366.                         filendx = filendx + 11;
  367.                         len = find_endofline(&(thefile[filendx]));
  368.                         if (len > extractlen)
  369.                            {
  370.                            extract = (char *) realloc ( (void *) extract, len + 10);
  371.                            extractlen = len + 10;
  372.                            }
  373.                         strncpy(extract, &(thefile[filendx]),len);
  374.                         extract[len] = '\0';
  375.                         set_alt_command(tmpicn, extract);
  376.                         }
  377.                      else if (Books)
  378.                         {
  379.                         do_format_error(linecount);
  380.                         }
  381.                      }
  382.                   else if ((cmp_rslt = strncasecmp("Geom Icon File", &(thefile[filendx]), 14)) == 0)
  383.                      {
  384.                      if (Demos)
  385.                         {
  386.                         filendx = filendx + 15;
  387.                         len = find_endofline(&(thefile[filendx]));
  388.                         strncpy(extract, &(thefile[filendx]),len);
  389.                         extract[len] = '\0';
  390.                         tmpicn->geofile = add_file(extract);
  391.                         }
  392.                      else if (Books)
  393.                         {
  394.                         do_format_error(linecount);
  395.                         }
  396.                      }
  397.                   else if ((cmp_rslt = strncasecmp("Img Icon File", &(thefile[filendx]), 13)) == 0)
  398.                      {
  399.                      if (Demos)
  400.                         {
  401.                         filendx = filendx + 14;
  402.                         len = find_endofline(&(thefile[filendx]));
  403.                         strncpy(extract, &(thefile[filendx]),len);
  404.                         extract[len] = '\0';
  405.                         tmpicn->imgfile = add_file(extract);
  406.                         }
  407.                      else if (Books)
  408.                         {
  409.                         do_format_error(linecount);
  410.                         }
  411.                      }
  412.                   else if ((cmp_rslt = strncasecmp("Help", &(thefile[filendx]), 4)) == 0)
  413.                      {
  414.                      filendx = filendx + 5;
  415.                      len = find_endofline(&(thefile[filendx]));
  416.                      strncpy(extract, &(thefile[filendx]),len);
  417.                      extract[len] = '\0';
  418.                      if (Demos)
  419.                         tmpicn->helpfile = add_file(extract);
  420.                      else if (Books)
  421.                         tmpgrp->helpfile = add_file(extract);
  422.                      }
  423.                   else if ((cmp_rslt = strncasecmp("File", &(thefile[filendx]), 4)) == 0)
  424.                      {
  425.                      if (Demos)
  426.                         {
  427.                         filendx = filendx + 5;
  428.                         if (tmpfile == NULL)
  429.                            {
  430.                            tmpicn->addtlfiles = (struct filelist *)malloc(sizeof(struct filelist) );
  431.                            tmpfile = tmpicn->addtlfiles;
  432.                            }
  433.                         else
  434.                            {
  435.                            tmpfile->next = (struct filelist *)malloc(sizeof(struct filelist) );
  436.                            tmpfile = tmpfile->next;
  437.                            }
  438.                         tmpfile->next = NULL;
  439.                         len = find_endofline(&(thefile[filendx]));
  440.                         strncpy(extract, &(thefile[filendx]),len);
  441.                         extract[len] = '\0';
  442.                         tmpfile->file = add_file(extract);
  443.                         if (tmpicn->ok && !tmpfile->file->ok)
  444.                            {
  445.                            tmpicn->ok = FALSE;
  446.                            }
  447.                         }
  448.                      else if (Books)
  449.                         {
  450.                         do_format_error(linecount);
  451.                         }
  452.                      }
  453.                   else if ((cmp_rslt = strncasecmp("Keyword", &(thefile[filendx]), 7)) == 0)
  454.                      {
  455.                      filendx = filendx + 8;
  456.                      len = find_endofline(&(thefile[filendx]));
  457.                      strncpy(extract, &(thefile[filendx]),len);
  458.                      extract[len] = '\0';
  459.                      check_ending_blanks(extract, len);
  460.                      if (Demos)
  461.                         {
  462.                         (tmpicn->numkey)++;
  463.                         if (tmpkey == NULL)
  464.                            {
  465.                            tmpicn->keywords = (struct wordlist *)malloc(sizeof(struct wordlist) );
  466.                            tmpkey = tmpicn->keywords;
  467.                            }
  468.                         else
  469.                            {
  470.                            tmpkey->next = (struct wordlist *)malloc(sizeof(struct wordlist) );
  471.                            tmpkey = tmpkey->next;
  472.                            }
  473.                         tmpkey->next = NULL;
  474.                         tmpkey->indexptr = add_keyword(extract);
  475.                         if (tmpkey->indexptr != NULL)
  476.                            index_add_demo(tmpkey->indexptr, tmpicn);
  477.                         }
  478.                      else if (Books)
  479.                         {
  480.                          /* check for duplicate keywords */
  481.                         tmpname = find_keyword(extract);
  482.                         wordptr = tmpgrp->keywords;
  483.                         while (wordptr != NULL && wordptr->indexptr != tmpname)
  484.                            wordptr = wordptr->next;
  485.                         if (wordptr == NULL) /* no dup found */
  486.                            {
  487.                            (tmpgrp->numkey)++;
  488.                            if (tmpkey == NULL)
  489.                               {
  490.                               tmpgrp->keywords = (struct wordlist *)malloc(sizeof(struct wordlist) );
  491.                               tmpkey = tmpgrp->keywords;
  492.                               }
  493.                            else
  494.                               {
  495.                               tmpkey->next = (struct wordlist *)malloc(sizeof(struct wordlist) );
  496.                               tmpkey = tmpkey->next;
  497.                               }
  498.                            tmpkey->next = NULL;
  499.                            tmpkey->indexptr = add_keyword(extract);
  500.                            if (tmpkey->indexptr != NULL)
  501.                               index_add_group(tmpkey->indexptr, tmpgrp);
  502.                            }
  503.                         }
  504.                      }
  505.                   else if ((cmp_rslt = strncasecmp("Color", &(thefile[filendx]), 5)) == 0)
  506.                      {
  507.                      if (Demos)
  508.                         {
  509.                         do_format_error(linecount);
  510.                         }
  511.                      else if (Books)
  512.                         {
  513.                         filendx = filendx + 6;
  514.                         if ((num_conv = sscanf(&(thefile[filendx])," %f %f %f",
  515.                             &tmpr, &tmpg, &tmpb)) == 3)
  516.                            {
  517.                            tmpgrp->covercolor[0] = tmpr;
  518.                            tmpgrp->covercolor[1] = tmpg;
  519.                            tmpgrp->covercolor[2] = tmpb;
  520.                            }
  521.                         }
  522.                      }
  523.                   else if ((cmp_rslt = strncasecmp("Demo", &(thefile[filendx]), 4)) == 0)
  524.                      {
  525.                      if (Demos)
  526.                         {
  527.                         do_format_error(linecount);
  528.                         }
  529.                      else if (Books)
  530.                         {
  531.                         filendx = filendx + 5;
  532.                         len = find_endofline(&(thefile[filendx]));
  533.                         strncpy(extract, &(thefile[filendx]),len);
  534.                         extract[len] = '\0';
  535.                         check_ending_blanks(extract, len);
  536.                         tmpname = find_keyword(extract);
  537.                         if (tmpname == NULL)
  538.                            {
  539.    sprintf(msgstring,"Demo %s not found in database\nline %d ascii file %s \n",
  540.          extract, linecount,FileName);
  541.    DialogType = 1;
  542.    popup_Message();
  543.                            }
  544.                         else
  545.                            {
  546.                         if (tmpicon == NULL)
  547.                            {
  548.                            tmpicon = (struct iconstruct *)malloc(sizeof(struct iconstruct) );
  549.                            if (tmppg == NULL)
  550.                               {
  551.                               tmppg = new_pg();
  552.                               tmpgrp->firstpage = tmppg;
  553.                               tmpgrp->lastpage = tmppg;
  554.                               tmppg->fronticons = tmpicon;
  555.                               }
  556.                            }
  557.                         else
  558.                            {
  559.                            tmpicon->nexticon = (struct iconstruct *)malloc(sizeof(struct iconstruct) );
  560.                            tmpicon = tmpicon->nexticon;
  561.                            }
  562.                         if (SIDE == FRONT)
  563.                            {
  564.                            tmppg->frontnumicons = tmppg->frontnumicons + 1;
  565.                            if (tmppg->frontnumicons > ICONLIMIT)
  566.                               setupgrp = tmpgrp;
  567.                            }
  568.                         else
  569.                            {
  570.                            tmppg->backnumicons = tmppg->backnumicons + 1;
  571.                            if (tmppg->backnumicons > ICONLIMIT)
  572.                               setupgrp = tmpgrp;
  573.                            }
  574.                         tmpicon->iconnum = 0;
  575.                         tmpicon->xposition_ndx = x;
  576.                         tmpicon->yposition_ndx = y;
  577.                         x++;
  578.                         if (x > 4)
  579.                            {
  580.                            x = 0;
  581.                            y--;
  582.                            if (y < 0)
  583.                               {
  584.                               x = 0;
  585.                               y = 3;
  586.                               }
  587.                            }
  588.                         tmpicon->nexticon = NULL;
  589.                         if (tmpname != NULL)
  590.                            {
  591.                  /* have to see if there is a duplicate icon with this name */
  592.                            if (dup_icn_cnt > 0)
  593.                               {
  594.                               i = 0;
  595.                               while (i < dup_icn_cnt && duplicate_icons[i]->nameptr != tmpname)
  596.                                  {
  597.                                  i++;
  598.                                  }
  599.                               if (i < dup_icn_cnt && duplicate_icons[i]->nameptr == tmpname)
  600.                                  tmpicon->iconptr = duplicate_icons[i];
  601.                               else 
  602.                                  tmpicon->iconptr = tmpname->icon;
  603.                               }
  604.                            else 
  605.                               tmpicon->iconptr = tmpname->icon;
  606.                            glist = tmpicon->iconptr->grps;
  607.                            tmpicon->iconptr->grps = (struct grpliststruct *)
  608.                                malloc(sizeof(struct grpliststruct) );
  609.                            tmpicon->iconptr->grps->prev = NULL;
  610.                            tmpicon->iconptr->grps->next = glist;
  611.                            if (glist != NULL)
  612.                               glist->prev = tmpicon->iconptr->grps;
  613.                            tmpicon->iconptr->grps->grpptr = tmpgrp;
  614.                            tmpicon->ok = tmpicon->iconptr->ok;
  615.                            (tmpicon->iconptr->occurences)++;
  616.                            }
  617.                            }
  618.                         }
  619.                      }
  620.                   else 
  621.                      {
  622.                      strncpy(extract, &(thefile[filendx]),len);
  623.                      extract[len] = '\0';
  624.                      sprintf(msgstring, "Error with line %d in file %s \n <%s>",
  625.                               linecount,FileName, extract);
  626.                      DialogType = 1;
  627.                      popup_Message();
  628.                      }
  629.                   }
  630.                len = find_endofline(&(thefile[filendx]));
  631.                filendx = filendx+len +1;
  632.                }
  633.             }
  634.          }
  635.       }
  636.      /* check to see if previous group had demos in it */
  637.    if (tmpgrp != NULL && (tmpgrp->firstpage == NULL || tmpgrp->firstpage->frontnumicons == 0))
  638.       {
  639.       sprintf(msgstring, " Deleting empty book %s \n",tmpgrp->nameptr->string);
  640.       DialogType = 1;
  641.       popup_Message();
  642.                            DeleteGroupFlag = TRUE;
  643.       deletegroup(tmpgrp);
  644.                            DeleteGroupFlag = FALSE;
  645.       }
  646.    else if (tmpgrp != NULL)
  647.       {
  648.       fix_grp_ok(tmpgrp);
  649.       }
  650.    if (lastgroup != NULL && lastgroup->firstpage->frontnumicons > ICONLIMIT)
  651.       {
  652.       group_setup(NULL, NULL,lastgroup);
  653.       }
  654.    initbookpos();
  655.    check_index();
  656.    ask_user_duplicate_icons(dup_icn_cnt);
  657.    return(!FILEERR);
  658. }
  659.  
  660. write_ascii(char *FileName)
  661. {
  662.    FILE *ofp;
  663.    struct icntmpltstruct *tmpicn;
  664.    struct filelist *tmpfile;
  665.    struct grptmpltstruct *tmpgrp;
  666.    struct pagestruct *tmppg;
  667.    struct wordlist *tmpkey;
  668.    struct iconstruct *tmpicon;
  669.  
  670.    if ( (ofp = fopen(FileName,"w")) == NULL)
  671.       {
  672.       sprintf(msgstring, "Could not open file \n%s\nfor output ...\nFile will not be written.",FileName);
  673.       DialogType = 1;
  674.       popup_Message();
  675.       }
  676.    else
  677.       {
  678.    fprintf(ofp, "Demobook ASCII file version %f \n",ascii_version);
  679.    fprintf(ofp, "#\n");
  680.    fprintf(ofp, "#\n");
  681.    fprintf(ofp, "Demo List\n");
  682.    tmpicn = firsticon;
  683.    while (tmpicn != NULL)
  684.       {
  685.       fprintf(ofp, "\tName %s\n", tmpicn->nameptr->string);
  686.       fprintf(ofp, "\tCommand %s\n", tmpicn->startstring);
  687.       if (tmpicn->alt_command != NULL)
  688.          fprintf(ofp, "\tAltCommand %s\n", tmpicn->alt_command);
  689.       if (tmpicn->geofile != NULL)
  690.          fprintf(ofp, "\tGeom Icon File %s\n", tmpicn->geofile->name);
  691.       if (tmpicn->imgfile != NULL)
  692.          fprintf(ofp, "\tImg Icon File %s\n", tmpicn->imgfile->name);
  693.       tmpfile = tmpicn->addtlfiles;
  694.       while (tmpfile != NULL)
  695.          {
  696.          fprintf(ofp, "\tFile %s\n", tmpfile->file->name);
  697.          tmpfile = tmpfile->next;
  698.          }
  699.       tmpkey = tmpicn->keywords;
  700.       while (tmpkey != NULL)
  701.          {
  702.          fprintf(ofp, "\tKeyword %s\n", tmpkey->indexptr->string);
  703.          tmpkey = tmpkey->next;
  704.          }
  705.       fprintf(ofp, "#\n");
  706.       tmpicn = tmpicn->nexticntmplt;
  707.       }
  708.    fprintf(ofp, "#\n");
  709.    fprintf(ofp, "#\n");
  710.    fprintf(ofp, "Book List\n");
  711.    tmpgrp = firstgroup;
  712.    while (tmpgrp != NULL)
  713.       {
  714.       fprintf(ofp, "\tName %s\n", tmpgrp->nameptr->string);
  715.       fprintf(ofp, "\tColor %f %f %f\n", tmpgrp->covercolor[0],
  716.              tmpgrp->covercolor[1], tmpgrp->covercolor[2]);
  717.       tmpkey = tmpgrp->keywords;
  718.       while (tmpkey != NULL)
  719.          {
  720.          fprintf(ofp, "\tKeyword %s\n", tmpkey->indexptr->string);
  721.          tmpkey = tmpkey->next;
  722.          }
  723.       tmppg = tmpgrp->firstpage;
  724.       tmpicon = tmppg->fronticons;
  725.       while (tmpicon  != NULL)
  726.          {
  727.          fprintf(ofp, "\tDemo %s\n", tmpicon->iconptr->nameptr->string);
  728.          tmpicon = tmpicon->nexticon;
  729.          }
  730.       fprintf(ofp, "#\n");
  731.       tmpgrp = tmpgrp->nextgrp;
  732.       }
  733.    fclose(ofp);
  734.    sprintf(msgstring, "\nSaved the ascii Demobook file\n%s\n", FileName);
  735.    popup_Message();
  736.       }
  737. }
  738.  
  739.